package Socket.test.DBUtils;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.junit.Test;
import javax.sql.DataSource;
import java.sql.*;

public class Login {

    static DataSource dataSource  = new ComboPooledDataSource();

    public static String  login(String username, String password) throws SQLException {

        QueryRunner runner = new QueryRunner(dataSource);
        String sql = "select * from users where name = ? and password = ?";
        User resutl = runner.query(sql, new BeanHandler<User>(User.class), username, password);
        if(resutl!=null){
            return "<html><h1><i>success</i></h1></html>";
        }
        return "<html><h1><i>error</i></h1></html>";
    }

    @Test
    public void fun() throws SQLException {
      String swt = login("admin","admin123");
      System.out.println(swt);
    }

}
